<style lang="less">
  @import '../styles/common.less';
  @import '../tables/components/table.less';
</style>

<template>
  <div>
    <Row :gutter="10">
      <Card>
        <div class="table-head">
          <Button type="primary" class="Button" @click="ExportData()">导出数据</Button>
          <Button type="primary" class="Button" @click="importData()">导入数据</Button>
          <a href="/vendors/Excel/socialRepo.xlsx" download="社会智库导入模板.xlsx">
            <Button type="primary" class="Button">下载模板</Button>
          </a>
        </div>
        <Row class="margin-top-10">
          <Table stripe border :columns="columns" :data="data" @on-row-click="onRowData"
                 @on-selection-change="selectionChange"></Table>
        </Row>
        <div style="margin: 10px;overflow: hidden;height: 36px;">
          <div style="float: right;">
            <Page :total="total" :current="page" @on-change="changePage" show-elevator></Page>
          </div>
        </div>
      </Card>
      <Modal :width="600" title="详情"
             v-model="showCurrentTableData"
             ok-text="确定"
             cancel-text="取消"
             @on-ok=""
             @on-cancel=""
             class-name="vertical-center-modal"
             class="Modal-Detail-div">
        <Form label-position="top">
          <FormItem label="信息采集状态">
            <div class="dataDetail-div" v-text="dataDetail_status"></div>
          </FormItem>
          <FormItem label="住户地址" v-if="dataDetail.address">
            <div class="dataDetail-div" v-text="dataDetail.address"></div>
          </FormItem>
          <FormItem label="拜访纪录" v-if="logArr.length > 0">
            <div class="dataDetail-div Timeline">
              <Timeline v-if="logArr.length > 0">
                <TimelineItem v-for="(el,index) in logArr " :key="index">
                  <p class="time" v-text="el.create_time"></p>
                  <p class="content" v-text="el.content"></p>
                </TimelineItem>
              </Timeline>
            </div>
          </FormItem>
          <FormItem label="居住类型" v-if="dataDetail.type">
            <div class="dataDetail-div" v-text="dataDetail.type ? dataDetail.type.title : ''"></div>
          </FormItem>
          <FormItem label="居住人数" v-if="dataDetail.people_number">
            <div class="dataDetail-div" v-text="dataDetail.people_number"></div>
          </FormItem>
          <FormItem label="户主姓名" v-if="dataDetail.full_name">
            <div class="dataDetail-div" v-text="masterObj.full_name"></div>
          </FormItem>
          <FormItem label="户主身份证号" v-if="dataDetail.id_number">
            <div class="dataDetail-div" v-text="masterObj.id_number"></div>
          </FormItem>
          <FormItem label="户主性别">
            <div class="dataDetail-div">
              {{masterObj.sex == 'male' ? '男' : ''}}
              {{masterObj.sex == 'female' ? '女' : ''}}
            </div>
          </FormItem>
          <FormItem label="户主手机号" v-if="dataDetail.phone">
            <div class="dataDetail-div" v-text="masterObj.phone"></div>
          </FormItem>
          <FormItem label="其他住户信息" v-if="otherArr.length > 0">
            <div class="dataDetail-div other-div">
              <div class="otherarr" v-for="el in otherArr">
                <table border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td class="title">与户主关系</td>
                    <td v-text="el.identity?el.identity.title:''"></td>
                  </tr>
                  <tr>
                    <td class="title">姓名</td>
                    <td v-text="el.full_name"></td>
                  </tr>
                  <tr>
                    <td class="title">性别</td>
                    <td>
                      {{el.sex == 'male' ? '男' : ''}}
                      {{el.sex == 'female' ? '女' : ''}}
                    </td>
                  </tr>
                  <tr>
                    <td class="title">身份证号</td>
                    <td v-text="el.id_number"></td>
                  </tr>
                  <tr>
                    <td class="title">手机号</td>
                    <td v-text="el.phone"></td>
                  </tr>
                </table>
              </div>
            </div>
          </FormItem>
          <FormItem label="备注" v-if="dataDetail.remark">
            <div class="dataDetail-div" v-text="dataDetail.remark"></div>
          </FormItem>
        </Form>
      </Modal>
      <!--编辑-->
      <Modal v-model="addCurrentTableData" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">编辑</h3>
        <Form label-position="top">
          <FormItem label="当前录入">
            <div class="dataDetail-div" v-text="addData.title"></div>
          </FormItem>
          <FormItem label="居住类型">
            <Select v-model="addData.type" style="width:100%;" :transfer="true">
              <Option v-for="item in HouseTypeArr" :value="item.id" :key="item.id">{{ item.title }}</Option>
            </Select>
          </FormItem>
          <FormItem label="居住人数">
            <InputNumber :max="1000" :min="1" v-model="addData.people_number" class="InputNumber"></InputNumber>
          </FormItem>
          <FormItem label="户主姓名">
            <Input v-model="addData.master_name" placeholder="户主姓名"></Input>
          </FormItem>
          <FormItem label="户主性别">
            <Select v-model="addData.master_sex" style="width:100%;" :transfer="true">
              <Option v-for="item in sexArr" :value="item.id" :key="item.id">{{ item.title }}</Option>
            </Select>
          </FormItem>
          <FormItem label="户主身份证号">
            <Input v-model="addData.master_id_number" placeholder="户主身份证号"></Input>
          </FormItem>
          <FormItem label="户主身手机号">
            <Input v-model="addData.master_phone" placeholder="户主身手机号"></Input>
          </FormItem>
          <FormItem label="其他住户信息">
            <div class="dataDetail-div other-add-div">
              <div class="line">
                <span></span>
                <span class="add-menu" @click="showOtherFormFun()">
                  <Icon type="md-add"/>
                </span>
              </div>
              <div class="line" v-for="el in addData.otherArr">
                <span v-text="el.identity.title"></span>
                <span class="menu" @click="delOtherdata(el.id)">
                  <Icon type="md-remove"/>
                </span>
              </div>
              <Form label-position="top" v-show="showOtherForm == true">
                <FormItem label="与户主关系">
                  <Select v-model="otherData.identity" style="width:100%;" :transfer="true">
                    <Option v-for="item in HoldIdentityArr" :value="item.id" :key="item.id">{{ item.title }}</Option>
                  </Select>
                </FormItem>
                <FormItem label="姓名">
                  <Input v-model="otherData.name" placeholder="户主姓名"></Input>
                </FormItem>
                <FormItem label="性别">
                  <Select v-model="otherData.sex" style="width:100%;" :transfer="true">
                    <Option v-for="item in sexArr" :value="item.id" :key="item.id">{{ item.title }}</Option>
                  </Select>
                </FormItem>
                <FormItem label="身份证号">
                  <Input v-model="otherData.id_number" placeholder="户主身份证号"></Input>
                </FormItem>
                <FormItem label="身手机号">
                  <Input v-model="otherData.phone" placeholder="户主身手机号"></Input>
                </FormItem>
                <FormItem label="">
                  <div class="button">
                    <Button type="primary" @click="hideOtherFormFun()">取消</Button>
                    <Button type="primary" @click="saveOtherdata()">确定</Button>
                  </div>
                </FormItem>
              </Form>
            </div>
          </FormItem>
          <FormItem label="信息是否完善">
            <i-switch v-model="addData.over" size="large">
              <span slot="open">是</span>
              <span slot="close">否</span>
            </i-switch>
          </FormItem>
          <FormItem label="备注">
            <Input v-model="addData.remark" type="textarea" class="textarea_resize"
                   :autosize="{minRows: 3}" placeholder="备注信息"></Input>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideAddModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="save()">确定</Button>
        </div>
      </Modal>
      <!--导入-->
      <Modal v-model="importDataModal" :width="600" :mask-closable="false" :closable="false"
             class-name="vertical-center-modal" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">导入信息</h3>
        <Form label-position="top">
          <FormItem label="上传附件">
            <div class="dataDetail-div chooseUser accessory">
              <div class="users" v-for="el in importDataArr">
                <span class="span-name" v-text="el.name"></span>
                <span class="span-icon" @click="delimportData(el)">
                  <Icon type="close-round"></Icon>
                </span>
              </div>
              <Upload v-if="importDataArr.length == 0"
                      :before-upload="handleUpload" action="">
                <Button icon="ios-cloud-upload-outline">选择文件</Button>
              </Upload>
            </div>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideImportDataModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveImportData()">确定</Button>
        </div>
      </Modal>
    </Row>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import Util from '../../libs/util';
  import Utils from '../../libs/mod.utils';
  import String from '../../libs/mod.string';
  import Modal from '../../libs/mod.Modal';
  export default {
    components: {},
    data () {
      return {
        total: 0,
        page: 1,
        size: 10,
        id: '',
        showCurrentTableData: false,
        loading: true,
        showCurrentColumns: [],
        editInlineAndCellData: [],
        columns: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            key: 'community',
            title: '小区',
            render: (h, params) => {
              var name = params.row.community.name;
              return h('div', [
                h('span', name)
              ]);
            }
          },
          {
            key: 'address',
            title: '楼号',
          },
          {
            key: 'status',
            title: '状态',
            render: (h, params) => {
              var status = params.row.status;
              switch (status) {
                case 1 :
                case 2 :
                  status = '信息已完善';
                  break;
                case 3 :
                case 4 :
                case 5 :
                  status = '信息未完善';
                  break;
                case 6 :
                case 7 :
                  status = '拒绝配合信息完善';
                  break;
                case 8 :
                  status = '信息未采集';
                  break;
                case 9 :
                  status = '信息不需要采集';
                  break;
                default :
                  break;
              }
              return h('div', [
                h('span', status)
              ]);
            }
          },
          {
            title: 'Action',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('Button', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: e => {
                      e.stopPropagation();
                      var data = params.row;
                      this.update(data, params.index);
                    }
                  }
                }, '编辑信息')
              ]);
            }
          }
        ],
        data: [],
        dataDetail: {},
        masterObj: {},
        otherArr: [],
        logArr: [],
        dataDetail_status: '',
        initTable: [],
        addCurrentTableData: false,
        saveLoading: false,
        ajaxType: 'add',
        addData: {
          title: '',
          type: '',
          people_number: 1,
          master_hold_id: '',
          master_name: '',
          master_id_number: '',
          master_sex: '',
          master_phone: '',
          otherArr: [],
          remark: '',
          over: false,
        },
        otherData: {
          identity: '',
          name: '',
          id_number: '',
          sex: '',
          phone: '',
        },
        showOtherForm: false,
        selectionArr: [],
        HouseTypeArr: [],
        HoldIdentityArr: [],
        sexArr: [
          {
            id: 'male',
            title: '男'
          },
          {
            id: 'female',
            title: '女'
          }
        ],
        importDataModal: false,
        importDataArr: [],
        comePageTime: 0,// 进入页面的时间戳
      };
    },
    beforeMount: function () {
      var _this = this;
      var comePageTime = _this.comePageTime;
      var timestamp = new Date().getTime();
      _this.comePageTime = timestamp;
    },
    beforeDestroy: function () {
      var _this = this;
      var comePageTime = _this.comePageTime;
      var timestamp = new Date().getTime();
      var type = Util.constant.statistical_type.intell_lib.id;
      var seconds = Math.ceil((parseInt(timestamp) - parseInt(comePageTime)) / 1000);
      Util.statistical(_this, type, seconds);//保存数据
    },
    mounted () {
      this.getData();
      this.getHouseType();
      this.getHoldIdentity();
    },
    methods: {
      getData () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          community_name: '',//小区名
          full_name: '',//姓名
          id_number: '',//身份证号
          type: '',//信息是否完善end/notEnd
          page: _this.page,
          size: _this.size,
        };
        var params = {
          url: '/sd/social-repo/house/getHouseList',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.total = res.rows;
            _this.data = _data;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 居住类型
      getHouseType: function () {
        var _this = this;
        var data = {};
        var params = {
          url: '/house/type/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.HouseTypeArr = _data;
          } else {
            _this.$Message.error('查询居住类型信息失败!');
          }
        }
      },
      // 与户主关系
      getHoldIdentity: function () {
        var _this = this;
        var data = {};
        var params = {
          url: '/house/holdIdentity/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            _this.HoldIdentityArr = _data;
          } else {
            _this.$Message.error('查询与户主关系信息失败!');
          }
        }
      },
      handleSearch () {
        var _this = this;
        _this.page = 1;
        var searchConName = _this.searchConName;
      },
      changePage (page) {
        var _this = this;
        console.log('page', page);
        _this.page = page;
        _this.getData();
      },
      onRowData: function (data, index) {
        var _this = this;
        _this.show(index, data);
      },
      show: function (index, data) {
        var _this = this;
        var id = data.id;
        _this.id = id;
        var data = {
          house_id: _this.id,
        };
        var params = {
          url: '/sd/social-repo/house/queryHouse',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            var hold = _data.hold || [];
            var masterObj = {};
            var otherArr = [];
            for (var k in hold) {
              if (!hold[k]) {
                continue;
              }
              var is_master = hold[k].is_master;
              if (is_master == true) {
                masterObj = hold[k];
              } else {
                otherArr.push(hold[k]);
              }
            }
            var dataDetail_status = '';
            var status = _data.status;
            switch (status) {
              case 1 :
                dataDetail_status = '信息已完善。首次拜访时，积极配合的用户';
                break;
              case 2 :
                dataDetail_status = '信息已完善。多次拜访时，完成信息采集的用户';
                break;
              case 3 :
                dataDetail_status = '信息未完善。';
                break;
              case 4 :
                dataDetail_status = '信息未完善。首次拜访时，不在家的用户';
                break;
              case 5 :
                dataDetail_status = '信息未完善。多次拜访时，不在家的用户';
                break;
              case 6 :
                dataDetail_status = '拒绝配合信息完善。首次拜访时，拒绝配合信息采集的用户';
                break;
              case 7 :
                dataDetail_status = '拒绝配合信息完善。多次拜访时，拒绝配合信息采集的用户';
                break;
              case 8 :
                dataDetail_status = '信息未采集。未进行拜访的用户';
                break;
              case 9 :
                dataDetail_status = '信息不需要采集。该房屋无人居住';
                break;
              default :
                break;
            }
            _this.dataDetail_status = dataDetail_status;
            _this.masterObj = masterObj;
            _this.otherArr = otherArr;
            _this.logArr = _data.log || [];
            _this.dataDetail = _data;
            _this.showCurrentTableData = true;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      asyncOK: function () {
        var _this = this;
        _this.showCurrentTableData = false;
      },
      // 列表多选 选中数据
      selectionChange: function (selection) {
        var _this = this;
        _this.selectionArr = selection;
      },
      // 隐藏编辑页面
      hideAddModal: function () {
        var _this = this;
        _this.addCurrentTableData = false;
      },
      // 显示添加界面
      add: function () {
        var _this = this;
        _this.ajaxType = 'add';
        _this.addCurrentTableData = true;
      },
      // 保存数据
      save: function () {
        var _this = this;
        var title = _this.addData.title;
        var type = _this.addData.type;
        var people_number = _this.addData.people_number;
        var over = _this.addData.over;
        var remark = _this.addData.remark;
        var master_name = _this.addData.master_name;
        var master_id_number = _this.addData.master_id_number;
        var master_sex = _this.addData.master_sex;
        var master_phone = _this.addData.master_phone;
        if (type == '') {
          _this.$Message.error('请选择居住类型!');
          return false;
        }
        if (people_number == '') {
          _this.$Message.error('请填写居住人数!');
          return false;
        }
        if (master_name == '') {
          _this.$Message.error('请填写户主姓名!');
          return false;
        }
        if (master_sex == '') {
          _this.$Message.error('请选择户主性别!');
          return false;
        }
        var over_id = 3;
        if (over) {
          over_id = 2;
        }
        var data = {
          house_id: _this.id,
          house_type: type,
          people_number: people_number,
          status: over_id,
          remark: remark,
        };
        var params = {
          url: '/sd/social-repo/house/updateHouse',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.seaveMaster();
          } else {
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 保存户主信息
      seaveMaster: function () {
        var _this = this;
        var master_name = _this.addData.master_name;
        var master_id_number = _this.addData.master_id_number;
        var master_sex = _this.addData.master_sex;
        var master_phone = _this.addData.master_phone;
        var master_hold_id = _this.addData.master_hold_id;
        var data = {
          house_id: _this.id,
          hold_id: master_hold_id,
          full_name: master_name,
          id_number: master_id_number,
          sex: master_sex,
          is_master: true,
          phone: master_phone,
        };
        var url = '/sd/social-repo/house/addHouseHold';
        if (master_hold_id && master_hold_id != '') {
          url = '/sd/social-repo/house/updateHouseHold';
        }
        var params = {
          url: url,
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.getData();
            _this.addCurrentTableData = false;
            _this.addData.title = '';
            _this.addData.type = '';
            _this.addData.people_number = 1;
            _this.addData.master_name = '';
            _this.addData.master_hold_id = '';
            _this.addData.master_sex = '';
            _this.addData.master_phone = '';
            _this.addData.otherArr = [];
            _this.addData.remark = '';
            _this.addData.over = false;
          } else {
            _this.$Message.error('保存户主信息失败!');
          }
        }
      },
      // 显示添加其他住户
      showOtherFormFun: function () {
        var _this = this;
        _this.otherData.identity = '';
        _this.otherData.name = '';
        _this.otherData.id_number = '';
        _this.otherData.sex = '';
        _this.otherData.phone = '';
        _this.showOtherForm = true;
      },
      // 隐藏添加其他住户
      hideOtherFormFun: function () {
        var _this = this;
        _this.otherData.identity = '';
        _this.otherData.name = '';
        _this.otherData.id_number = '';
        _this.otherData.sex = '';
        _this.otherData.phone = '';
        _this.showOtherForm = false;
      },
      // 保存其他人员
      saveOtherdata: function () {
        var _this = this;
        var identity = _this.otherData.identity;
        var name = _this.otherData.name;
        var id_number = _this.otherData.id_number;
        var sex = _this.otherData.sex;
        var phone = _this.otherData.phone;
        if (identity == '') {
          _this.$Message.error('请选择与户主关系!');
          return false;
        }
        if (name == '') {
          _this.$Message.error('请填写姓名!');
          return false;
        }
        if (sex == '') {
          _this.$Message.error('请选择性别!');
          return false;
        }
        var identityTitle = '';
        var HoldIdentityArr = _this.HoldIdentityArr;
        for (var k in HoldIdentityArr) {
          if (!HoldIdentityArr[k]) {
            continue;
          }
          if (identity == HoldIdentityArr[k].id) {
            identityTitle = HoldIdentityArr[k].title;
            break;
          }
        }
        var data = {
          house_id: _this.id,
          full_name: name,
          id_number: id_number,
          sex: sex,
          identity: identity,
          is_master: false,
          phone: phone,
        };
        var params = {
          url: '/sd/social-repo/house/addHouseHold',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var id = res.data.id;
            var obj = {
              id: id,
              full_name: name,
              id_number: id_number,
              identity: {
                id: identity,
                title: identityTitle,
              },
              is_master: false,
              phone: phone,
              sex: sex,
            };
            _this.addData.otherArr.push(obj);
            _this.hideOtherFormFun();
          } else {
            _this.$Message.error('保存信息失败!');
          }
        }
      },
      // 删除其他住户
      delOtherdata: function (id) {
        var _this = this;
        var data = {
          hold_id: id,
        };
        var params = {
          url: '/sd/social-repo/house/deleteHouseHold',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            // 删除数组的元素
            var otherArr = _this.addData.otherArr;
            for (var i = 0; i < otherArr.length; i++) {
              var iid = otherArr[i].id;
              if (id == iid) {
                var del = otherArr.splice(i, 1);
                break;
              }
            }
            _this.addData.otherArr = otherArr;
          } else {
            _this.$Message.error('删除信息失败!');
          }
        }
      },
      // 显示修改界面
      update: function (data, index) {
        var _this = this;
        _this.ajaxType = 'update';
        var id = data.id;
        _this.id = id;
        var data = {
          house_id: _this.id,
        };
        var params = {
          url: '/sd/social-repo/house/queryHouse',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            var hold = _data.hold || [];
            var masterObj = {};
            var otherArr = [];
            for (var k in hold) {
              if (!hold[k]) {
                continue;
              }
              var is_master = hold[k].is_master;
              if (is_master == true) {
                masterObj = hold[k];
              } else {
                otherArr.push(hold[k]);
              }
            }
            _this.addData.title = _data.address;
            _this.addData.type = _data.type.id;
            _this.addData.people_number = _data.people_number;
            _this.addData.master_hold_id = masterObj.id;
            _this.addData.master_name = masterObj.full_name;
            _this.addData.master_id_number = masterObj.id_number;
            _this.addData.master_sex = masterObj.sex;
            _this.addData.master_phone = masterObj.phone;
            _this.addData.otherArr = otherArr;
            _this.addData.remark = _data.remark;

            _this.addCurrentTableData = true;
          } else {
            _this.$Message.error('查询信息失败!');
          }
        }
      },
      // 删除
      remove: function () {
        var _this = this;
        var selectionArr = _this.selectionArr;
        if (selectionArr.length == 0) {
          _this.$Message.error('请填选择要删除的数据!');
          return false;
        }
        var selectionIds = [];
        for (var k in selectionArr) {
          if (!selectionArr[k]) {
            continue;
          }
          var id = selectionArr[k].id;
          selectionIds.push(id);
        }
        Modal.confirm(_this, {content: '确定删除选中的信息？'}, function () {
          var data = {
            //id: selectionIds,
            house_id: id
          };
          var params = {
            url: '/sd/social-repo/house/ResetupdateHouse',
            type: Util.method.get,
            data: data,
            success: _successFun
          };
          Util.ajax(_this, params);
          function _successFun(res) {
            if (res.result == 0) {
              _this.page = 1;
              _this.getData();
            } else {
              _this.$Message.error('删除信息失败!');
            }
          }
        }, function () {
        });
      },
      // 导出
      ExportData: function () {
        var _this = this;
        var fields = [
          {
            field: 'department_name',
            title: '居委会',
            type: 'varchar',
            order: 1,
          },
          {
            field: 'cname',
            title: '小区名称',
            type: 'varchar',
            order: 2,
          },
          {
            field: 'bname',
            title: '楼号',
            type: 'varchar',
            order: 3,
          },
          {
            field: 'uname',
            title: '单元号',
            type: 'varchar',
            order: 4,
          },
          {
            field: 'fname',
            title: '楼层',
            type: 'varchar',
            order: 5,
          },
          {
            field: 'house_number',
            title: '门牌号',
            type: 'varchar',
            order: 6,
          },
          {
            field: 'type',
            title: '居住类型',
            type: 'varchar',
            order: 7,
          },
          {
            field: 'people_number',
            title: '居住人数',
            type: 'varchar',
            order: 8,
          },
          {
            field: 'full_name',
            title: '姓名',
            type: 'varchar',
            order: 9,
          },
          {
            field: 'sex',
            title: '性别',
            type: 'varchar',
            order: 10,
          },
          {
            field: 'id_number',
            title: '身份证号',
            type: 'varchar',
            order: 11,
          },
          {
            field: 'phone',
            title: '手机号',
            type: 'varchar',
            order: 12,
          },
          {
            field: 'is_master',
            title: '是否户主',
            type: 'varchar',
            order: 13,
          },
          {
            field: 'identity',
            title: '与户主关系',
            type: 'varchar',
            order: 14,
          },
          {
            field: 'status',
            title: '信息采集状态',
            type: 'varchar',
            order: 15,
          },
          {
            field: 'remark',
            title: '备注',
            type: 'varchar',
            order: 16,
          },
        ];
        var fieldsStr = Util.toStr(fields);
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          type: 'house',
          fields: fieldsStr,
        };
        var params = {
          url: '/file/db2excle',
          type: Util.method.post,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var url = res.data;
            var date = Utils.dateToDateString(new Date());
            Utils.DownloadFile(url, '导出社会智库信息_' + date + '.xlsx');
          } else {
            _this.$Message.error('导出信息失败!');
          }
        }
      },
      // 导入
      importData: function () {
        var _this = this;
        _this.importDataArr = [];
        _this.importDataModal = true;
      },
      // 取消导入
      hideImportDataModal: function () {
        var _this = this;
        _this.importDataArr = [];
        _this.importDataModal = false;
      },
      // 确定导入
      saveImportData: function () {
        var _this = this;
        if (_this.importDataArr.length == 0) {
          _this.$Message.error('请上传附件!');
          return false;
        }
        var file_id = _this.importDataArr[0].id;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          fid: file_id
        };
        var params = {
          url: '/sd/social-repo/importExcel',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.page = 1;
            _this.getData();
            _this.hideImportDataModal();
          } else {
            _this.$Message.error('导入信息失败!');
          }
        }
      },
      // 选中文件
      handleUpload: function (file) {
        var _this = this;
        _this.UploadFile(file);
        return false;
      },
      // 上传文件
      UploadFile: function (file) {
        var _this = this;
        var name = file.name;
        var arr = name.split('.');
        var type = arr[1];
        if (type != 'xlsx') {
          _this.$Message.error('请上传xlsx文件!');
          return false;
        }
        var formData = new FormData();
        formData.append("file", file);
        formData.append("action", "UploadVMKImagePath");
        var params = {
          url: '/file/addFile',
          type: Util.method.post,
          data: formData,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data;
            var id = data.id;
            var name = data.name;
            var url = data.url;
            var obj = {
              id: id,
              name: name,
              url: url,
            };
            _this.importDataArr.push(obj);
          } else {
            _this.$Message.error('上传失败!');
          }
        }
      },
      // 删除附件
      delimportData: function (el) {
        var _this = this;
        var id = el.id;
        var importDataArr = _this.importDataArr;
        for (var k in importDataArr) {
          if (!importDataArr[k]) {
            continue;
          }
          if (id == importDataArr[k].id) {
            var del = importDataArr.splice(k, 1);
            break;
          }
        }
        _this.importDataArr = importDataArr;
      },
    }
  };
</script>
